/**
 * Created by zlq on 2017/9/30.
 */


var page = 1;
var id;


function doAjax(){
    $.ajax({
        url:'/crm/integralGoods/search.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            page:page,
            name:$('#name').val(),
            state:$('#state').val(),
        },
        type:'post',
        success: function (data) {
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==0){
                alert(data.msg);
            }
            if(data.code==1){
                $('#record').html(data.recordsTotal);
                $('#withdraw-record').empty();
                console.log(data.datas.length)
                for(var i=0;i<data.datas.length;i++){

                    $('<tr class="gradeA odd">'+
                        '<a href=""><td class="detailsId" style="text-decoration: underline;cursor: pointer;" id="'+data.datas[i].id+'">'+data.datas[i].id+'</td></a>'+
                        '<td class="center ">'+data.datas[i].name+'</td>'+
                        '<td class="sorting_1">'+data.datas[i].abbreviation+'</td>'+
                        '<td class="center ">'+data.datas[i].unitIntegral +'</td>'+
                        '<td class="center ">'+data.datas[i].totalIntegral+'</td>'+
                        '<td class="center ">'+data.datas[i].inventory+'</td>'+
                        '<td class=" center">'+data.datas[i].state+'</td>'+
                        '<td class=" center">'+data.datas[i].goodsType+'</td>'+
                        '</tr>').appendTo($('#withdraw-record'));
                }

                $(".pagination").createPage({
                    totalPage:data.totalPage,
                    currPage:data.pageNow,
                    pageCount:data.pageNow,
                    turndown:'true',
                    backFn:function(p){
                        page=p;
                        doAjax();
                    }
                });

                $('.detailsId').click(function(){
                    var applyId = $(this).attr('id');
                    window.location.href="/crm/integralGoods/detailsView?id="+applyId;
                })

            }
        }
    })
}

$(function(){
    doAjax();
})




//查询
$('#refer').click(function(){
    stateValue = $('#state').val();
    page=1;
    doAjax();
})


$('#add').click(function () {
    window.location.href="/crm/integralGoods/addView"
})